<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/9/29
 * Time: 15:38
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Notes extends Base{
    /**
     * 列表展示
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax()){
            $map = array();
            extract(input());
            if(isset($balance_type)&&$balance_type!="")
            {
                $map['balance_type'] = ['like',"%" . $balance_type . "%"];
            }
            if(isset($balance_status)&&$balance_status!="")
            {
                $map['balance_status'] = $balance_status;
            }
            if(isset($start) && $start != '' && isset($end) && $end != ''){
                $map['balance_time'] = ['between', [$start, $end]];
            }
            if(isset($start) && $start != '' && isset($end) && $end == ''){
                $map['balance_time'] = ['> time', $start];
            }
            if(isset($start) && $start == '' && isset($end) && $end != ''){
                $map['balance_time'] = ['< time', $end];
            }
            $map['a.balance_xs'] =2;
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('user_balance')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->where($map)->count();// 获取总条数
            $lists = Db::name('user_balance')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->where($map)
                ->page($NowPage,$limits)
                ->field('a.*,uuu.user_username')
                ->order('balance_id desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
}